package cn.hn.tx.mail;

//import org.springframework.mail.SimpleMailMessage;
//import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class SimpleMailSender {

	public static void main(String[] args) {
		String result = SimpleMailSender.SendMail("smtp.qq.com", "602835713",
				"19840302d", "119shenhao@163.com", "602835713@qq.com",
				"javamail test测试", "test 测试");
		System.out.println(result);
		// Mail mail = new Mail();
		// mail.sendMsg("602835713", "19840302d", "stmp.qq.com",
		// "119shenhao@163.com", "602835713@qq.com", "javamail test测试",
		// "test 测试");
	}

	public static String SendMail(String host, String userName,
			String password, String toAddress, String fromAddress,
			String subject, String text) {
		JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
		// 设定mail server
		senderImpl.setHost(host);
		senderImpl.setUsername(userName);
		senderImpl.setPassword(password);

		// 建立邮件消息
		SimpleMailMessage mailMessage = new SimpleMailMessage();
		// 设置收件人，寄件人
		// String[] array = new String[] {"sun111@163.com","sun222@sohu.com"};
		// mailMessage.setTo(array);
		mailMessage.setTo(toAddress);
		mailMessage.setFrom(fromAddress);
		mailMessage.setSubject(subject);
		mailMessage.setText(text);

		// 发送邮件
		senderImpl.send(mailMessage);

		return "邮件发送成功";
	}

	public static String SendMails(String host, String userName,
			String password, String[] toAddresses, String fromAddress,
			String subject, String text) {
		JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
		// 设定mail server
		senderImpl.setHost(host);
		senderImpl.setUsername(userName);
		senderImpl.setPassword(password);

		// 建立邮件消息
		SimpleMailMessage mailMessage = new SimpleMailMessage();
		// 设置收件人，寄件人
		// String[] array = new String[] {"sun111@163.com","sun222@sohu.com"};
		mailMessage.setTo(toAddresses);
		mailMessage.setFrom(fromAddress);
		mailMessage.setSubject(subject);
		mailMessage.setText(text);

		// 发送邮件
		senderImpl.send(mailMessage);

		return "邮件发送成功";
	}
}
